/*************************************************************************
	> File Name: hzk.c
	> Author: life
	> Created Time: Tue 29 Mar 2022 10:43:06 AM CST
 ************************************************************************/

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>


struct stat hzk_stat;
unsigned char *hzkmem;

int main(int argc,char *argv[])
{
	unsigned char hzk[] = "";  //D6D0
	unsigned char buffer[32];
	unsigned int bytes[16];
	printf("GBK %02x %02x \n",hzk[0],hzk[1]);

	int fd = open("./GB2312_H1616.FON",O_RDONLY);
	fstat(fd, &hzk_stat);
	
	hzkmem = (unsigned char *)mmap(NULL , hzk_stat.st_size, PROT_READ, MAP_SHARED, fd, 0);
	
	unsigned char *dots = hzkmem + ((hzk[0]-0xa1)*94+hzk[1]-0xa1)*16*16/8;

	memcpy(buffer,dots,32);
	int i, j, b;

	for (i = 0;i < 32;i++)
	{
		printf("%02x  ",buffer[i]);
	}
	printf("\n");
	for (i = 0;i < 16;i++)
	{
		bytes[i] = buffer[i * 2] << 8 | buffer[i * 2 + 1];
	}
	
	for (i = 0;i < 16;i++)
	{
		printf("%04x  ",bytes[i]);
	}
	printf("\n");
	for (j = 0; j < 16; j++) {
		for (i = 0; i < 16; i++) {
			if (bytes[j] & (1<<(15 - i)))
				printf("*");
			else
				printf(" ");
		}
		printf("\n");
	}
	
    return 0;
}




